﻿@{
    ViewBag.Title = "OrderIndex";
    Layout = "~/Views/Users/Index.cshtml";
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<link href="~/css/bootstrap.css" rel="stylesheet" />
<script src="~/js/jquery.min.js"></script>
<script src="~/js/bootstrap.min.js"></script>

<script>
    $(function () {
        $.ajax({
            type: "post",
            url: "/Order/OrderIndexs",
            success: function (obj)
            {
                $("#tds").empty();
                for (var i = 0; i < obj.length; i++)
                {
                    $("#tds").append("<tr><td>" + obj[i].OrderID + "</td><td>" + obj[i].UserTel + "</td><td>" + obj[i].Delivery_address + "</td><td>" + obj[i].Distribution_form + "</td><td>" + obj[i].Paymethod + "</td><td>" + obj[i].Place_Time + "</td><td>" + obj[i].OrderState + "</td><td><input type='button' value='接受'  name='Jie" + i + "'  onclick='OrderUpt(" + obj[i].OrderID + ")'  class='btn btn-success' /><input type='button' value='完成'  name='Full" + i + "'  onclick='OrderFull(" + obj[i].OrderID + ")'  class='btn btn-success' /><input type='button' value='明细'  class='btn btn-success' data-toggle='modal' data-target='#modal_add_user'   onclick='SelectAll(" + obj[i].OrderID + ")' /></td></tr>");


                    if (obj[i].OrderState=="正在配送") {
                        $("[name='Jie" + i + "']").hide();
                        $("[name='Full" + i + "']").show();
                    }
                    if (obj[i].OrderState == "正在进行")
                    {
                        $("[name='Jie" + i + "']").show();
                        $("[name='Full" + i + "']").hide();
                    }
                    if (obj[i].OrderState == "已完成") {
                        $("[name='Jie" + i + "']").hide();
                        $("[name='Full" + i + "']").hide();
                    }
                }
            }
        })
    })
    function SelectAll(id)
    {
        $.ajax({
            type: "post",
            url: "/Order/SelectAll",
            data: { OrderID: id },
            success: function (obj)
            {
                $("#tdss").empty();
                var Suma = 0;
                for (var i = 0; i < obj.length; i++)
                {
                    var Sums = obj[i].purchaseNumber * obj[i].Sales_unit_price;
                    Suma += Sums;
                    $("#tdss").append("<tr><td>" + obj[i].OrderID + "</td><td>" + obj[i].FlowersName + "</td><td id='Num'>" + obj[i].purchaseNumber + "</td><td><img src='" + obj[i].FlowersImg + "' style ='width:35px;height:35px'/></td><td id='Pri'>" + obj[i].Sales_unit_price + "</td><td>" + Sums + "</td></tr>");
                }
                $("#spans").text(Suma);
            }
        })
    }
    function SelectPay()
    {

        var Pay = $("#ses").val();
        if (Pay == "----请选择----") {
            alert("请选择类型");
        }
        else {
            $.ajax({
                type: "post",
                url: "/Order/OrderSelectPay",
                data: { PayId: Pay },
                success: function (obj) {
                    $("#tds").empty();
                    for (var i = 0; i < obj.length; i++) {
                        $("#tds").append("<tr><td>" + obj[i].OrderID + "</td><td>" + obj[i].UserTel + "</td><td>" + obj[i].Delivery_address + "</td><td>" + obj[i].Distribution_form + "</td><td>" + obj[i].Paymethod + "</td><td>" + obj[i].Place_Time + "</td><td>" + obj[i].OrderState + "</td><td><input type='button' value='接受' id='Jie'  onclick='OrderUpt(" + obj[i].OrderID + ")'  class='btn btn-success' /><input type='button' value='明细'  class='btn btn-success' data-toggle='modal' data-target='#modal_add_user'   onclick='SelectAll(" + obj[i].OrderID + ")' /></td></tr>");
                    }
                }
            })
        }
    }

    function ShowAll()
    {
        location.href='/Order/OrderIndex'
    }

    function OrderUpt(id)
    {
        $.ajax({
            type: "post",
            url: "/Order/OrderUpta",
            data: { OrderID: id },
            success: function (obj)
            {
                if (obj > 0) {
                    alert("接受成功,正在配送");
                    location.href = '/Order/OrderIndex';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }

    function OrderFull(id)
    {
        $.ajax({
            type: "post",
            url: "/Order/OrderFull",
            data: { OrderID: id },
            success: function (obj) {
                if (obj > 0) {
                    alert("已配送完成");
                    location.href = '/Order/OrderIndex';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }

</script>


<span style="font-size:18px">
    支付方式:
</span>
<select id="ses"><option>----请选择----</option><option>货到付款</option><option>在线支付</option></select><input type="button" value="查询" onclick="SelectPay()" class="btn btn-success" /><input type="button" value="显示全部" onclick="ShowAll()" class="btn btn-success" />
<table class="table table-responsive" style="border:solid 1px;">
    <tr>
        <td>订单编号</td>
        <td>用户手机</td>
        <td>送货地址</td>
        <td>配送形式</td>
        <td>支付方式</td>

        <td>下单时间</td>
        <td>订单状态</td>
        <td>操作</td>

    </tr>
    <tbody id="tds"></tbody>
</table>


<div class="modal fade" id="modal_add_user" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>订单详情</strong></h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped">
                    <tr>
                        <td>订单编号</td>
                        <td>花卉名称</td>
                        <td>购买数量</td>
                        <td>图片</td>
                        <td>单价</td>
                        <td>金额</td>
                    </tr>
                    <tbody id="tdss"></tbody>
                </table>
                <span style="font-size:18px">总价:</span>  <span id="spans" style="font-size:18px"></span>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>
